package com.acwing.partition17;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/9 18:08
 */
public class AC1696困牛排序 {

    private static final int N = 110;
    private static int[] seq = new int[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        String[] ss = reader.readLine().split(" ");
        for (int i = 1; i <= n; i++) seq[i] = Integer.parseInt(ss[i - 1]);
        boolean flag = false;
        for (int i = n - 1; i > 0; i--) {
            if (seq[i] > seq[i + 1]) {
                writer.write(i + "\n");
                flag = true;
                break;
            }
        }
        if (!flag) writer.write("0\n");
        writer.flush();
    }
}
